﻿using LogBookImporter.Implementation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tester.Interface;

namespace Tester.Tests {
    public class LogBookParserTester : ITester {

        #region Private Fields

        private List<string> _errors =  new List<string>();

        #endregion


        #region Constructors

        public LogBookParserTester() {
            Errors = new List<string>();
        }

        #endregion

        
        #region Properties

        public List<string> Errors {
            get;
            set;
        }

        #endregion

        
        #region Public Methods

        public void Run() {
            TestParseMainLine();
            TestParseFileLocation();
            TestParseAngles();
            TestParseScans();
            TestParseResolution();
            TestParseDateTimeFromFileLocation();
        }

        #endregion


        #region Private Methods

        private void TestParseMainLine() {
            
        }

        private void TestParseFileLocation() {
            string inputString = @"C:\\DEV\\Ellipsometer\\LogBookCrawler\\LogBookCrawler\\bin\\Debua   2";
            string result = LogBookLineParser.ParseFileLocation(inputString);
            if (result != @"C:\\DEV\\Ellipsometer\\LogBookCrawler\\LogBookCrawler\\bin\\Debub") {
                Errors.Add(string.Format(@"LineParserTester: LineParser.ParseFileLocation(...). Result is {0}, but should be 'C:\\DEV\\Ellipsometer\\LogBookCrawler\\LogBookCrawler\\bin\\Debub'", result));
            }


            inputString = @"C:\\DEV\\Ellipsometer\\LogBookCrawler\\LogBookCrawler\\bin\\Debua   1";
            result = LogBookLineParser.ParseFileLocation(inputString);
            if (result != @"C:\\DEV\\Ellipsometer\\LogBookCrawler\\LogBookCrawler\\bin\\Debua") {
                Errors.Add(string.Format(@"LineParserTester: LineParser.ParseFileLocation(...). Result is {0}, but should be 'C:\\DEV\\Ellipsometer\\LogBookCrawler\\LogBookCrawler\\bin\\Debua'", result));
            }

            inputString = @"C:\\DEV\\Ellipsometer\\LogBookCrawler\\LogBookCrawler\\bin\\Debua   5";
            result = LogBookLineParser.ParseFileLocation(inputString);
            if (result != @"C:\\DEV\\Ellipsometer\\LogBookCrawler\\LogBookCrawler\\bin\\Debue") {
                Errors.Add(string.Format(@"LineParserTester: LineParser.ParseFileLocation(...). Result is {0}, but should be 'C:\\DEV\\Ellipsometer\\LogBookCrawler\\LogBookCrawler\\bin\\Debue'", result));
            }
        }

        private void TestParseAngles() {
            string inputString = "80.5/-35.2";
            double[] result = LogBookLineParser.ParseAngles(inputString);
            if (result[0] != (double)80.5) {
                Errors.Add(string.Format("LineParserTester: LineParser.TestParseAngles(...). Result is {0} but should be 80.5", result));
            }
            if (result[1] != (double)-35.2) {
                Errors.Add(string.Format("LineParserTester: LineParser.TestParseAngles(...). Result is {0} but should be -35.2", result));
            }

            inputString = " 80.5/-35.2 ";
            result = LogBookLineParser.ParseAngles(inputString);
            if (result[0] != (double)80.5) {
                Errors.Add(string.Format("LineParserTester: LineParser.TestParseAngles(...). Result is {0} but should be 80.5", result));
            }
            if (result[1] != (double)-35.2) {
                Errors.Add(string.Format("LineParserTester: LineParser.TestParseAngles(...). Result is {0} but should be -35.2", result));
            }

            inputString = "80/-35";
            result = LogBookLineParser.ParseAngles(inputString);
            if (result[0] != (double)80) {
                Errors.Add(string.Format("LineParserTester: LineParser.TestParseAngles(...). Result is {0} but should be 80", result));
            }
            if (result[1] != (double)-35) {
                Errors.Add(string.Format("LineParserTester: LineParser.TestParseAngles(...). Result is {0} but should be -35", result));
            }
        }

        private void TestParseScans() {
            string inputString = "8 scans";
            int result = LogBookLineParser.ParseScans(inputString);
            if (result != 8) {
                Errors.Add(string.Format("LineParserTester: LineParser.TestParseScans(...). Result is {0} but should be 8", result));
            }
        }

        private void TestParseResolution() {
            string inputString = "res=4";
            double result = LogBookLineParser.ParseResolution(inputString);
            if (result != 4) {
                Errors.Add(string.Format("LineParserTester: LineParser.ParseResolution(...). Result is {0} but should be 4", result));
            }
        }

        private void TestParseDateTimeFromFileLocation() {
            string time = "04:20";
            string fileLocation = @"C:\elli\0802feb\\feb25a";
            DateTime dateTime = new DateTime(2008, 2, 25, 4, 20, 0);
            DateTime result = LogBookLineParser.ParseDateTimeFromFileLocation(time, fileLocation);

            if (!dateTime.Equals(result)) {
                Errors.Add(string.Format("LineParserTester: LineParser.ParseDateTimeFromFileLocation(...). Result is {0} but should be 25.02.2008 04:20", result));
            }

            time = "4:20";
            result = LogBookLineParser.ParseDateTimeFromFileLocation(time, fileLocation);

            if (!dateTime.Equals(result)) {
                Errors.Add(string.Format("LineParserTester: LineParser.ParseDateTimeFromFileLocation(...). Result is {0} but should be 25.02.2008 04:20", result));
            }

            time = "4:2";
            dateTime = new DateTime(2008, 2, 25, 4, 2, 0);
            result = LogBookLineParser.ParseDateTimeFromFileLocation(time, fileLocation);

            if (!dateTime.Equals(result)) {
                Errors.Add(string.Format("LineParserTester: LineParser.ParseDateTimeFromFileLocation(...). Result is {0} but should be 25.02.2008 04:02", result));
            }

            time = "04:2";
            result = LogBookLineParser.ParseDateTimeFromFileLocation(time, fileLocation);

            if (!dateTime.Equals(result)) {
                Errors.Add(string.Format("LineParserTester: LineParser.ParseDateTimeFromFileLocation(...). Result is {0} but should be 25.02.2008 04:02", result));
            }
        }

        #endregion

        
    }
}
